// pages/login/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    username:'',
    password:'',
    cText:'',
    cValue:[],
    cId:'',
    companyData:[],
    hidezh:true,
    hideCompany:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getCompany();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
wx.hideHomeButton()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  setUserName(e){
    let name=e.detail.value;
    this.setData({
      username:name
    })
  },
  setPass(e){
    let pass=e.detail.value;
   this.setData({
     password:pass
   })
  },
  login(){
    let that=this;
    console.log('ddd',that.data)
    if(that.data.cId==''){
      wx.showToast({
        title: '请选择企业',
        icon:'error'
      })

      return false;
    }
    if (that.data.username==''){
    wx.showToast({
      title: '请输入账号密码',
      icon:'error'
    })
    return
    }
    let param={
      cId:that.data.cId,
      phone:that.data.username,
      // password:that.data.password
    };
    app.common.http_post('/miniProgram/Action/login',param,function(res){
      var userInfo = res.data
  
      wx.setStorageSync('userInfo', userInfo);
      wx.redirectTo({
        url: '/pages/index/index',
      })
      // app.common.go_to('/pages/index/index')
    })
  
  },
  getCompany(){
    let that=this;
    app.common.http_post('/miniProgram/action/getCompany',{},function(res){
          let data=res.data;
         that.setData({companyData:data});
        })
  }, 
  cPicker(){
    this.setData({ cVisible: true});
  },
  selectPicker(e){
    console.log('eee',e)
    let pickName = e.currentTarget.dataset.key;
      let pickValue = e.detail.value;
      console.log('dddddd',e.detail.value)
    this.setData({
      [`${pickName}Visible`]: false,
      [`${pickName}Value`]:  pickValue,
      [`${pickName}Id`]:  pickValue.join(','),
      [`${pickName}Text`]: e.detail.label.join(' '),
      hidezh:false,hideCompany:true
    });
    console.log('data',this.data)
  },
  onPickerCancel(e){
    const { key } = e.currentTarget.dataset.key;
  
    this.setData({
      [`${key}Visible`]: false,
    });
  },
})